package com.jeehentor.system.controller;


import com.jeehentor.common.vo.Result;
import com.jeehentor.dto.MenuDTO;
import com.jeehentor.entity.SysMenu;
import com.jeehentor.system.service.ISysMenuService;
import com.jeehentor.vo.MenuVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 系统菜单表 前端控制器
 * </p>
 *
 * @author wzd
 * @since 2024-04-01
 */
@RestController
@RequestMapping("/menu")
@RequiredArgsConstructor
@Tag(name = "系统菜单")
public class SysMenuController {

    private final ISysMenuService sysMenuService;

    @Operation(summary = "添加菜单")
    @PostMapping("/addMenu")
//    @PreAuthorize("hasAuthority('sys:menu:add')")
    public Result<String> addMenu(@RequestBody MenuDTO menuDTO){
        sysMenuService.addMenu(menuDTO);
        return Result.ok("添加成功");
    }

    @Operation(summary = "修改菜单")
    @PostMapping("/updateMenu")
//    @PreAuthorize("hasAuthority('sys:menu:edit')")
    public Result<String> updateMenu(@RequestBody MenuDTO menuDTO){
        sysMenuService.updateMenu(menuDTO);
        return Result.ok("修改成功");
    }

    @Operation(summary = "删除菜单")
    @PostMapping("/deleteMenu")
    public Result<String> deleteMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.deleteMenu(sysMenu);
        return Result.ok("删除成功");
    }

    @Operation(summary = "菜单列表")
    @PostMapping("/list")
    public Result<List<MenuVO>> list(@RequestBody MenuDTO menuDTO){
        List<MenuVO> menuList = sysMenuService.menuList(menuDTO);
        return Result.ok(menuList);
    }

    @Operation(summary = "菜单详情")
    @PostMapping("/detail")
    public Result<MenuVO> detail(@RequestBody SysMenu sysMenu){
        MenuVO menuDetail = sysMenuService.menuDetail(sysMenu);
        return Result.ok(menuDetail);
    }

    @Operation(summary = "用户路由")
    @PostMapping("/getRouter")
    public Result<List<MenuVO>> getRouter(){
        List<MenuVO> menuRouter = sysMenuService.getRouter();
        return Result.ok(menuRouter);
    }
}
